﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleAppwww
{
    class Student

    {

        public string Name { get; set; }

        public bool Gender { get; set; }

        public string Course { get; set; }//课程

        public int Score { get; set; }//成绩

        public int Age { get; set; }

    }

    class Program
    {

        static void Main()
        {

           List<Student> list = new List<Student>(){

            new Student(){Name="冰焰",Gender=true,Course="C#程序设计",Score=80,Age=20},

            new Student(){Name="蓝加",Gender=true,Course="C#程序设计",Score=66,Age=19},

            new Student(){Name="冰焰",Gender=true,Course="Web应用开发",Score=70,Age=20},

            new Student(){Name="蓝加",Gender=true,Course="Web应用开发",Score=80,Age=19},

            new Student(){Name="清奇",Gender=false,Course="C#程序设计",Score=90,Age=19},

            new Student(){Name="少腾",Gender=true,Course="大学英语",Score=89,Age=19},

            new Student(){Name="小萍",Gender=false,Course="大学英语",Score=95,Age=19},

            new Student(){Name="丹竹",Gender=true,Course="概率统计",Score=56,Age=19},

            new Student(){Name="令国",Gender=true,Course="法学",Score=90,Age=19},

            new Student(){Name="仁宏",Gender=true,Course="国际政治",Score=87,Age=20},

            new Student(){Name="仁宏",Gender=true,Course="国际事务及国际关系",Score=77,Age=20},

            new Student(){Name="仁宏",Gender=true,Course="政治学与行政学",Score=89,Age=20}


        };
            //请分别完成以下LINQ语句实现：

            //1、找出参加Web应用开发课程的学生数据，并按成绩进行降序排序。
            var querya = from s in list
                         where s.Course == "Web应用开发"
                         orderby s.Score descending
                         select s;
            foreach (var item in querya)
            {
                Console.WriteLine($"姓名：{item.Name},课程：{item.Course},分数{item.Score},年龄{item.Age}");
            }


            //2、查找课程为大学英语的学生，并按年龄、成绩进行排序。
            var querya1 = from d in list
                          where d.Course == "大学英语"
                          orderby d.Age
                          orderby d.Score
                          select d;
            foreach (var item in querya1)
            {
                Console.WriteLine($"{item.Name},年龄{item.Age},{item.Course}，成绩{item.Score}");
            }




            //3、查找《C#程序设计》成绩最低的学生信息。
            var querya2 = from s in list
                          where s.Course == "C#程序设计"
                          group s by s.Course
                          into zdScore
                          select new
                          {
                              课程 = zdScore.Key,
                              最低成绩 = zdScore.Min(x => x.Score)

                          };
            foreach (var item in querya2)
            {
                Console.WriteLine($"{item}");
            }



            //4、查找仁宏的成绩信息，并计算出仁宏的总成绩、平均成绩。
            var querya3 = from h in list
                          where h.Name == ("仁宏")
                          group h by h.Name into w
                          select new
                          {
                              姓名 = w.Key,
                              总成绩 = w.Sum(x => x.Score),
                              平均成绩 = w.Average(x => x.Score)
                          };
            foreach (var item in querya3)
            {
                Console.WriteLine($"{item}");
            }

            //5、将list列表内容以6行数据为一页进行分页查询，并按页显示。
            int pageSize = 6;
            int pageIndex = 0;
            while (pageIndex * pageSize < list.Count)
            {
                var pageList = (from p in list
                                select p).Skip(pageIndex * pageSize).Take(pageSize);
                Console.WriteLine("第{0}页数据", pageIndex + 1);
                foreach (var item in pageList)
                {
                    Console.WriteLine($"{item.Name},{item.Course},{item.Score},{item.Age}");
                }
                pageIndex++;
            }




            Console.ReadKey();
        }

    }


}
